package com.wust.menu;

import com.wust.R;

import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ImageBtn extends LinearLayout {
	private ImageView imagev=null;
	private TextView textv_name=null;
	private TextView textv_state=null;
	private String user_name;
	private String icon;
	private String info;
	public ImageBtn(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}
	public ImageBtn(Context context,AttributeSet attrs) {
		super(context,attrs);
		// TODO Auto-generated constructor stub
		SharedPreferences sp =context.getSharedPreferences("userinfo",0);
		user_name=sp.getString("user_nickname", "");
		icon=sp.getString("user_icon", "");
		info=sp.getString("info", "");
		LayoutInflater inflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		inflater.inflate(R.layout.head, this);
		imagev=(ImageView)findViewById(R.id.head_view);
		textv_name=(TextView)findViewById(R.id.net_name);
		textv_state=(TextView)findViewById(R.id.net_state);
		Bitmap bitmap=BitmapFactory.decodeFile(icon);
		Drawable drawable=new BitmapDrawable(bitmap);
		imagev.setBackgroundDrawable(drawable); 
		textv_name.setText(user_name);
		textv_state.setText(info);
	}
	public void setImageResource(int resid){
		imagev.setBackgroundResource(resid);
	}
	public void setTextViewName(String text){
		textv_name.setText(text);
	}
	public void setTextViewState(String text){
		textv_state.setText(text);
	}
}
